package com.longdaji.decoration.ui.activitiesOfMine.pendingReceiving;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.bean.MyLogistics;
import com.longdaji.decoration.bean.Orders;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.data.network.HttpResponse;
import com.longdaji.decoration.utils.LogUtil;
import com.longdaji.decoration.utils.RxUtil;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Kanade on 2018/4/30 0030.
 */

public class SeeLogisticsPresenter extends RxPresenter<SeeLogisticsContract.IView> implements SeeLogisticsContract.IPresenter {
    private DataManager mDataManager;

    private static final String TAG = "SeeLogisticsPresenter";

    @Inject
    public SeeLogisticsPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }

    @Override
    public void initOrder(String orderNo) {
//        addSubscribe(mDataManager.doGetOrderApi(Account.getInstance().getUserid(), null, orderNo)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .compose(RxUtil.<Orders>handleResult())
//                .subscribeWith(new CommonSubscriber<Orders>() {
//                    @Override
//                    public void onSuccess(Orders orders) {
//                        if (orders.getOrders().getOrder().size() != 1) {
//                            LogUtil.d(TAG, "get order error");
//                            return;
//                        }
//                        Orders.OrdersBean.OrderBean order = orders.getOrders().getOrder().get(0);
//                        mView.showInitOrder(order);
//                    }
//
//                    @Override
//                    public void onFailed(String msg) {
//
//                    }
//                }));

        addSubscribe(mDataManager.doSeeLogisticsApi(orderNo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtil.<MyLogistics>handleResult())
                .subscribeWith(new CommonSubscriber<MyLogistics>() {
                    @Override
                    public void onSuccess(MyLogistics myLogistics) {
                        LogUtil.i("success doSeeLogisticsApi: " + myLogistics.toString());
                        mView.showInitLogistics(myLogistics);
                    }

                    @Override
                    public void onFailed(String msg) {
                        LogUtil.i("fail doSeeLogisticsApi: " + msg);
                    }
                }));

    }
}
